package com.kaola.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.kaola.dao.CategoryDAO;
import com.kaola.pojo.Category;

public class CategoryDAOImpl extends HibernateTemplate implements CategoryDAO {

	public void add(Category category) {
		save(category);
	}

	public List<Category> listForLevel1() {
		return find("from Category c where c.grade=?", Category.LEVEL1);
	}

	public List<Category> listForLevel2(Category cLevel1) {
		return find("from Category c where c.grade=? and c.category=?", Category.LEVEL2, cLevel1);
	}

	public List<Category> listForLevel3(Category cLevel2) {
		return find("from Category c where c.grade=? and c.category=?", Category.LEVEL3, cLevel2);
	}

	public List<Category> listAllLevel2() {
		return find("from Category c where c.grade=?", Category.LEVEL2);
	}
	
	public List<Category> listAllLevel3() {
		return find("from Category c where c.grade=?", Category.LEVEL3);
	}
	
	public List<Category> listAll() {
		return find("from Category c");
	}
	
	public void delete(int id) {
		delete(get(Category.class, id));
	}
}
